﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DomainDriver.DomainModeling.StorageManagers.EntityFrameworkStorage
{
    public class StoredKeyBasedEqualityComparer<STORED_KEY, DOMAIN_OBJECT> : IEqualityComparer<DOMAIN_OBJECT>
        where DOMAIN_OBJECT : IEfEntity<STORED_KEY>
    {
        public virtual bool Equals(DOMAIN_OBJECT x, DOMAIN_OBJECT y)
        {
            if ((x == null) || (y == null))
            { throw new InvalidOperationException("The objects to compare must not be null."); }

            return x.EF_Id.Equals(y.EF_Id);
        }

        public virtual int GetHashCode(DOMAIN_OBJECT obj)
        {
            return obj.EF_Id.GetHashCode();
        }
    }
}